//
//  YRJSearchResultViewController.m
//  YanRenjie
//
//  Created by dllo on 15/11/3.
//  Copyright (c) 2015年 yanrenjie. All rights reserved.
//

#import "YRJSearchResultViewController.h"
#import "YRJTripHeader.h"

@interface YRJSearchResultViewController ()<UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate, YRJSearchResultDiscountTableViewCellDelegate, UIAlertViewDelegate>
@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, retain)NSMutableArray *searchResultDestinationArray;
@property(nonatomic, retain)NSMutableArray *searchResultPostsArray;
@property(nonatomic, retain)NSMutableArray *searchResultDiscountArray;
@property(nonatomic, retain)NSMutableArray *searchResultUserArray;
@end

NSInteger searchResultDestinationPageIndex = 1;
NSInteger searchResultPostsPageIndex = 1;
NSInteger searchResultDiscountPageIndex = 1;
NSInteger searchResultUserPageIndex = 1;
@implementation YRJSearchResultViewController

- (void)dealloc {
    [_keyString release];
    [_searchTextString release];
    [_scrollView release];
    [_searchResultDestinationArray release];
    [_searchResultDiscountArray release];
    [_searchResultPostsArray release];
    [_searchResultUserArray release];
    
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = self.searchTextString;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"首页" style:UIBarButtonItemStylePlain target:self action:@selector(backHomeAction:)];
    
    [self createScrollViewButton];
    
    [self createScrollView];
    
    [self createTableView];
}


#pragma mark - 创建上面的那个导航菜单
- (void)createScrollViewButton {
    NSArray *titleNameArray = [NSArray arrayWithObjects:@"目的地", @"帖子", @"折扣", @"用户", nil];
    for (NSInteger i = 0; i < 4; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(WIDTH / 4 * i, 0, WIDTH / 4, (40.0 / 667) * HEIGHT);
        button.layer.borderWidth = 1;
        [button setTitle:titleNameArray[i] forState:UIControlStateNormal];
        [self.view addSubview:button];
        button.tag = 2000 + i;
        [button addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    
}


#pragma mark - 导航菜单上按钮的点击方法
- (void)clickAction:(UIButton *)button {
    NSInteger titleButtonIndex = button.tag - 2000;
    self.scrollView.contentOffset = CGPointMake(titleButtonIndex * WIDTH, 0);
}


#pragma mark - 创建一个scrollView
- (void)createScrollView {
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, (40.0 / 375) * WIDTH, WIDTH, HEIGHT)];
    [self.view addSubview:self.scrollView];
    self.scrollView.backgroundColor = [UIColor cyanColor];
    self.scrollView.pagingEnabled = YES;
    [_scrollView release];
    self.scrollView.contentSize = CGSizeMake(WIDTH * 4, 0);
    self.scrollView.delegate = self;
}


#pragma mark 当滑动结束, 稳定之后才会被触发
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
    NSInteger scrollViewPageIndex = scrollView.contentOffset.x / WIDTH;
    UIButton *button = (UIButton *)[self.view viewWithTag:(scrollViewPageIndex + 2000)];
}


#pragma mark - 创建tableView
- (void)createTableView {
    for (NSInteger i = 0; i < 4; i++) {
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
        tableView.tag = 1000 + i;
        [self.scrollView addSubview:tableView];
        tableView.dataSource = self;
        tableView.delegate = self;
        [tableView release];
        [self create:tableView];
    }
}


- (void)create:(UITableView *)tableView {
    NSInteger tableViewIndex = [tableView tag] - 1000;
    if (tableViewIndex == 0) {
        [self createDestinationTableView:tableView];   // 目的地
    } else if (tableViewIndex == 1) {
        [self createPostsTableView:tableView];   // 帖子
    } else if (tableViewIndex == 2) {
        [self createDiscountTableView:tableView];   // 折扣偶
    } else {
        [self createUserTableView:tableView];   // 用户
    }
}


//pragma mark - 分别写4个tableView
#pragma mark - 目的地的tableView
- (void)createDestinationTableView:(UITableView *)tableView {
    [self createDestinationData:tableView];
    tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(searchResultDestinationRefresh)];
    tableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        searchResultDestinationPageIndex++;
        [self searchResultDestinationLoading:tableView];
    }];
}


- (void)createDestinationData:(UITableView *)tableView {
    NSString *strURL = [NSString stringWithFormat:@"%@%@%@%ld%@", @"http://open.qyer.com/qyer/search/index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&keyword=", self.keyString, @"&page=", searchResultDestinationPageIndex, @"&place_field=country%7Ccity%7Cpoi&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=AB5B28ED-8670-4190-873A-F09EFE3EB3E8&track_os=ios%25207.1.2&type=place&v=1"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:strURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        self.searchResultDestinationArray = [YRJSearchDestinationModel baseModelByArr:dic[@"data"][@"entry"]];
        if (self.searchResultDestinationArray.count == 0) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"暂无搜索结果, 谢谢!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
            alert.delegate = self;
            [alert show];
        } else {
            [tableView reloadData];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}


#pragma mark - alertView 的协议方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    [self.navigationController popToRootViewControllerAnimated:YES];

}


#pragma mark - searchResultDestinationTableView 的上拉加载, 下拉刷新方法实现
- (void)searchResultDestinationLoading:(UITableView *)tableView {
    NSString *strURL = [NSString stringWithFormat:@"%@%@%@%ld%@", @"http://open.qyer.com/qyer/search/index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&keyword=", self.keyString, @"&page=", searchResultDestinationPageIndex, @"&place_field=country%7Ccity%7Cpoi&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=AB5B28ED-8670-4190-873A-F09EFE3EB3E8&track_os=ios%25207.1.2&type=place&v=1"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:strURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSMutableArray *tempArray = [YRJSearchDestinationModel baseModelByArr:dic[@"data"][@"entry"]];
        for (YRJSearchDestinationModel *tempModel in tempArray) {
            [self.searchResultDestinationArray addObject:tempModel];
        }
        [tableView reloadData];
        [tableView.header endRefreshing];
        [tableView.footer endRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}


- (void)searchResultDestinationRefresh {
    UITableView *tableView = (UITableView *)[self.view viewWithTag:1000];
    [self.searchResultDestinationArray removeAllObjects];
    [self searchResultDestinationLoading:tableView];
}


#pragma mark - 帖子的tableView
- (void)createPostsTableView:(UITableView *)tableView {
    [self createPostsData:tableView];
    tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(searchResultPostsRefresh)];
    tableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        searchResultPostsPageIndex++;
        [self searchResultPostsLoading:tableView];
    }];
}


- (void)createPostsData:(UITableView *)tableView {
    NSString *strURL = [NSString stringWithFormat:@"%@%@%@%ld%@", @"http://open.qyer.com/qyer/search/index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&keyword=", self.keyString, @"&page=", searchResultPostsPageIndex, @"&place_field=country%7Ccity%7Cpoi&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=AB5B28ED-8670-4190-873A-F09EFE3EB3E8&track_os=ios%25207.1.2&type=thread&v=1"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:strURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        self.searchResultPostsArray = [YRJSearchPostsModel baseModelByArr:dic[@"data"][@"entry"]];
        [tableView reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}


- (void)searchResultPostsLoading:(UITableView *)tableView {
    NSString *strURL = [NSString stringWithFormat:@"%@%@%@%ld%@", @"http://open.qyer.com/qyer/search/index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&keyword=", self.keyString, @"&page=", searchResultPostsPageIndex, @"&place_field=country%7Ccity%7Cpoi&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=AB5B28ED-8670-4190-873A-F09EFE3EB3E8&track_os=ios%25207.1.2&type=thread&v=1"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:strURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSMutableArray *tempArray = [YRJSearchPostsModel baseModelByArr:dic[@"data"][@"entry"]];
        for (YRJSearchPostsModel *tempModel in tempArray) {
            [self.searchResultPostsArray addObject:tempModel];
        }
        [tableView reloadData];
        [tableView.footer endRefreshing];
        [tableView.header endRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}


- (void)searchResultPostsRefresh {
    UITableView *tableView = (UITableView *)[self.view viewWithTag:1001];
    [self.searchResultPostsArray removeAllObjects];
    [self searchResultPostsLoading:tableView];
}


#pragma mark - 折扣的tableView
- (void)createDiscountTableView:(UITableView *)tableView {
    [self createDiscountData:tableView];
    tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(searchResultDiscountRefresh)];
    tableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        searchResultDiscountPageIndex++;
        [self searchResultDiscountLoading:tableView];
    }];
}


- (void)createDiscountData:(UITableView *)tableView {
    NSString *strURL = [NSString stringWithFormat:@"%@%@%@%ld%@", @"http://open.qyer.com/lastminute/app_lastminute_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&kw=", self.keyString, @"&page=", searchResultDiscountPageIndex, @"&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=AB5B28ED-8670-4190-873A-F09EFE3EB3E8&track_os=ios%25207.1.2&v=1"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:strURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        self.searchResultDiscountArray = [YRJSearchResultDiscountModel baseModelByArr:dic[@"data"][@"lastminutes"]];
        [tableView reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}


- (void)searchResultDiscountLoading:(UITableView *)tableView {
    NSString *strURL = [NSString stringWithFormat:@"%@%@%@%ld%@", @"http://open.qyer.com/lastminute/app_lastminute_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&kw=", self.keyString, @"&page=", searchResultDiscountPageIndex, @"&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=AB5B28ED-8670-4190-873A-F09EFE3EB3E8&track_os=ios%25207.1.2&v=1"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:strURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSMutableArray *tempArray = [YRJSearchResultDiscountModel baseModelByArr:dic[@"data"][@"lastminutes"]];
        for (YRJSearchResultDiscountModel *tempModel in tempArray) {
            [self.searchResultDiscountArray addObject:tempModel];
        }
        [tableView reloadData];
        [tableView.footer endRefreshing];
        [tableView.header endRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}


- (void)searchResultDiscountRefresh {
    UITableView *tableView = (UITableView *)[self.view viewWithTag:1002];
    [self.searchResultDiscountArray removeAllObjects];
    [self searchResultDiscountLoading:tableView];
}


#pragma mark - 用户的tableView
- (void)createUserTableView:(UITableView *)tableView {
    [self createUserData:tableView];
    tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(searchResultUserRefresh)];
    tableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        searchResultUserPageIndex++;
        [self searchResultUserLoading:tableView];
    }];
}


- (void)createUserData:(UITableView *)tableView {
    NSString *strURL = [NSString stringWithFormat:@"%@%@%@%ld%@", @"http://open.qyer.com/qyer/search/index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&keyword=", self.keyString, @"&page=", searchResultUserPageIndex, @"&place_field=country%7Ccity%7Cpoi&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=AB5B28ED-8670-4190-873A-F09EFE3EB3E8&track_os=ios%25207.1.2&type=user&v=1"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:strURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        self.searchResultUserArray = [YRJSearchResultUserModel baseModelByArr:dic[@"data"][@"entry"]];
        [tableView reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}


- (void)searchResultUserLoading:(UITableView *)tableView {
    NSString *strURL = [NSString stringWithFormat:@"%@%@%@%ld%@", @"http://open.qyer.com/qyer/search/index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&keyword=", self.keyString, @"&page=", searchResultUserPageIndex, @"&place_field=country%7Ccity%7Cpoi&track_app_channel=App%2520Store&track_app_version=6.8&track_device_info=iPhone%25204%28ChinaMobile%2CChinaUnicom%29&track_deviceid=AB5B28ED-8670-4190-873A-F09EFE3EB3E8&track_os=ios%25207.1.2&type=user&v=1"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:strURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = responseObject;
        NSMutableArray *tempArray = [YRJSearchResultUserModel baseModelByArr:dic[@"data"][@"entry"]];
        for (YRJSearchResultUserModel *tempModel in tempArray) {
            [self.searchResultUserArray addObject:tempModel];
        }
        [tableView reloadData];
        [tableView.header endRefreshing];
        [tableView.footer endRefreshing];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}


- (void)searchResultUserRefresh {
    UITableView *tableView = (UITableView *)[self.view viewWithTag:1003];
    [self.searchResultUserArray removeAllObjects];
    [self searchResultUserLoading:tableView];
}


#pragma mark - tableView 的协议方法----必须实现的两个协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView.tag == 1000) {
        return self.searchResultDestinationArray.count;
    } else if (tableView.tag == 1001) {
        return self.searchResultPostsArray.count;
    } else if (tableView.tag == 1002) {
        return 1;
    } else {
        return self.searchResultUserArray.count;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView.tag == 1000) {
        static NSString *searchResultDestinationReuse = @"searchResultDestinationReuse";
        YRJSearchResultDestinationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:searchResultDestinationReuse];
        if (!cell) {
            cell = [[YRJSearchResultDestinationTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:searchResultDestinationReuse];
        }
        if (self.searchResultDestinationArray.count != 0) {
            YRJSearchDestinationModel *tempModel = self.searchResultDestinationArray[indexPath.row];
            [cell.photoImageView sd_setImageWithURL:[NSURL URLWithString:tempModel.photo] placeholderImage:[UIImage imageNamed:@"placeHold.png"]];
            cell.cnnameLabel.text = tempModel.cnname;
            // 搜索关键字高亮
            NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:cell.cnnameLabel.text];
            [attribute addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[cell.cnnameLabel.text rangeOfString:self.searchTextString]];
            [cell.cnnameLabel setAttributedText:attribute];
            cell.ennameLabel.text = tempModel.enname;
            cell.beenStrLabel.text = tempModel.beenstr; 
        }
        return cell;
    } else if (tableView.tag == 1001) {
        static NSString *searchResultPostsReuse = @"searchResultPostsReuse";
        YRJSearchResultPostsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:searchResultPostsReuse];
        if (!cell) {
            cell = [[YRJSearchResultPostsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:searchResultPostsReuse];
        }
        if (self.searchResultPostsArray.count != 0) {
            YRJSearchPostsModel *tempModel = self.searchResultPostsArray[indexPath.row];
            [cell.photoImageView sd_setImageWithURL:[NSURL URLWithString:tempModel.photo] placeholderImage:[UIImage imageNamed:@"placeHold.png"]];
            cell.titleLabel.text = tempModel.title;
            // 关键字高亮
            NSMutableAttributedString *attributeOne = [[NSMutableAttributedString alloc] initWithString:cell.titleLabel.text];
            [attributeOne addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[cell.titleLabel.text rangeOfString:self.searchTextString]];
            [cell.titleLabel setAttributedText:attributeOne];
            
            cell.usernameLabel.text = tempModel.username;
            // 将时间戳转化为时间格式, 并截取其中的日期
            cell.lastpostLabel.text = [[NSString stringWithFormat:@"%@", [self timestampIntoTime:[tempModel.lastpost doubleValue]]] substringWithRange:NSMakeRange(0, 10)];
            cell.viewsLabel.text = [NSString stringWithFormat:@"%@%@%@", @"浏览(", tempModel.views, @")"];
            cell.replysLabel.text = [NSString stringWithFormat:@"%@%@%@", @"评论(", tempModel.replys, @")"];
        }
        return cell;
    } else if (tableView.tag == 1002) {
        static NSString *searchResultDiscountReuse = @"searchResultDiscountReuse";
        YRJSearchResultDiscountTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:searchResultDiscountReuse];
        if (!cell) {
            cell = [[YRJSearchResultDiscountTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:searchResultDiscountReuse];
        }
        cell.tempArray = self.searchResultDiscountArray;
        cell.searchResultString = self.searchTextString;
        // 设置代理人
        cell.delegate = self;
        return cell;
    } else {
        static NSString *searchResultUserReuse = @"searchResultUserReuse";
        YRJSearchResultUserTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:searchResultUserReuse];
        if (!cell) {
            cell = [[YRJSearchResultUserTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:searchResultUserReuse];
        }
        if (self.searchResultUserArray.count != 0) {
            YRJSearchResultUserModel *tempModel = self.searchResultUserArray[indexPath.row];
            [cell.avatarImageView sd_setImageWithURL:[NSURL URLWithString:tempModel.avatar] placeholderImage:[UIImage imageNamed:@"placeHold.png"]];
            cell.usernameLabel.text = tempModel.username;
            NSLog(@"%@<-------------->%@", cell.usernameLabel.text, tempModel.username);
            // 关键字高亮
            NSMutableAttributedString *attributeTwo = [[NSMutableAttributedString alloc] initWithString:cell.usernameLabel.text];
            [attributeTwo addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[cell.usernameLabel.text rangeOfString:self.searchTextString]];
            [cell.usernameLabel setAttributedText:attributeTwo];
            
            cell.titleLabel.text = [NSString stringWithFormat:@"%@|去过%@国家,去过%@个城市", tempModel.title, tempModel.countries, tempModel.cities];
        }
        return cell;
    }
}


#pragma mark - 将时间戳转化为时间
- (NSDate *)timestampIntoTime:(NSTimeInterval)time {
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:time];
    return confromTimesp;
}


#pragma mark - tableView 的非必须实现的协议方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView.tag == 1000) {
        return (130.0 / 667) * HEIGHT;
    } else if (tableView.tag == 1001) {
        return (130.0 / 667) * HEIGHT;
    } else if (tableView.tag == 1002) {
        return HEIGHT - 64;
    } else {
        return (120.0 / 667) * HEIGHT;
    }
}


#pragma mark - tableView 的cell的点击方法实现
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // 待实现
    if (tableView.tag == 1000) {
        YRJSearchDestinationModel *tempModel = self.searchResultDestinationArray[indexPath.row];
        if ([tempModel.type  isEqual: @3]) {
            YRJCountryDetailViewController *countryDetailVC = [[YRJCountryDetailViewController alloc] init];
            [self.navigationController pushViewController:countryDetailVC animated:YES];
            countryDetailVC.string = [NSString stringWithFormat:@"%@", tempModel.id];
            [countryDetailVC release];
        } else if ([tempModel.type isEqual:@2]) {
            YRJCityDetailViewController *cityDetailVC = [[YRJCityDetailViewController alloc] init];
            [self.navigationController pushViewController:cityDetailVC animated:YES];
            cityDetailVC.string = [NSString stringWithFormat:@"%@", tempModel.id];
            [cityDetailVC release];
        }
    } else if (tableView.tag == 1001) {
        YRJSearchResultPostsWebViewController *searchResultPostsWebVC = [[YRJSearchResultPostsWebViewController alloc] init];
        [self.navigationController pushViewController:searchResultPostsWebVC animated:YES];
        YRJSearchPostsModel *tempModel = self.searchResultPostsArray[indexPath.row];
        searchResultPostsWebVC.string = tempModel.view_url;
        [searchResultPostsWebVC release];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


#pragma mark - YRJSearchResultDiscountTableViewCellDelegate 的协议方法实现
- (void)pushToSearchResultDiscountWebViewController:(NSString *)string {
    YRJSearchResultDiscountWebViewController *searchResultDiscountWebVC = [[YRJSearchResultDiscountWebViewController alloc] init];
    [self.navigationController pushViewController:searchResultDiscountWebVC animated:YES];
    searchResultDiscountWebVC.string = string;
    [searchResultDiscountWebVC release];
}


#pragma mark - 返回首页操作 
- (void)backHomeAction:(UIButton *)button {
    [self.navigationController popToRootViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
